package com.lyh.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lyh.common.enums.*;
import com.lyh.system.domain.req.OrderWebReq;
import com.lyh.system.domain.req.RechargeRecordReq;
import com.lyh.system.domain.resp.OrderWebResq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lyh.common.annotation.Log;
import com.lyh.common.core.controller.BaseController;
import com.lyh.common.core.domain.AjaxResult;
import com.lyh.system.domain.RechargeRecord;
import com.lyh.system.service.IRechargeRecordService;
import com.lyh.common.utils.poi.ExcelUtil;
import com.lyh.common.core.page.TableDataInfo;

/**
 * 支付记录Controller
 *
 * @author ruoyi
 * @date 2023-04-27
 */
@Api(value = "充值管理",description = "充值管理")
@RestController
@RequestMapping("/app/record")
public class RechargeRecordController extends BaseController
{
    @Autowired
    private IRechargeRecordService rechargeRecordService;

    /**
     * 查询支付记录列表
     */

    @ApiOperation("充值管理-后台分页")
    @GetMapping("/list")
    public TableDataInfo list( RechargeRecordReq record)
    {
        startPage();
        List<RechargeRecord> list = rechargeRecordService.selectRechargeRecordList(record);
        if(list!=null && list.size()>0){
            list.stream().forEach(c->{
                c.setStatusName(RechargeStatusEnum.valueOf(c.getPaymentStatus()).getInfo());
            });
        }
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @Log(title = "充值明细导出", businessType = BusinessType.EXPORT)
    @ApiOperation("充值明细导出")
    @PostMapping("/export")
    public void  export(HttpServletResponse response,@RequestBody RechargeRecordReq req)
    {
        req.setPageNum(null);
        req.setPageSize(null);
        List<RechargeRecord> list = rechargeRecordService.selectRechargeRecordList(req);
        if(list!=null && list.size()>0){
            list.stream().forEach(c->{
                c.setStatusName(RechargeStatusEnum.valueOf(c.getPaymentStatus()).getInfo());
                c.setRechargeType(RechargeTypeEnum.valueOf(c.getRechargeType()).getInfo());
                c.setPaymentMethod(PaymentMethodEnum.valueOf(c.getPaymentMethod()).getTitle());
            });
        }
        ExcelUtil<RechargeRecord> util = new ExcelUtil<RechargeRecord>(RechargeRecord.class);
        util.exportExcel(response, list, "充值明细导出");
    }



    @ApiOperation("充值管理-汇总")
    @GetMapping("/webAllNum")
    public AjaxResult getWebAllNum(){
      return   AjaxResult.success(rechargeRecordService.getWebAllNum());
    }





    /**
     * 获取支付记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rechargeRecordService.selectRechargeRecordById(id));
    }

    /**
     * 新增支付记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "支付记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RechargeRecord rechargeRecord)
    {
        return toAjax(rechargeRecordService.insertRechargeRecord(rechargeRecord));
    }

    /**
     * 修改支付记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "支付记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RechargeRecord rechargeRecord)
    {
        return toAjax(rechargeRecordService.updateRechargeRecord(rechargeRecord));
    }

    /**
     * 删除支付记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "支付记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rechargeRecordService.deleteRechargeRecordByIds(ids));
    }
}
